package cn.zy.amyan.core.codec;

import cn.zy.amyan.core.util.AySerializer;
import cn.zy.amyan.core.util.KryoSerializer;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * 编码类
 * @author 子言
 * @date 2024/5/5 下午 15:40
 */
public class AyEncode extends MessageToByteEncoder {

	AySerializer serializerUtil = new KryoSerializer();

	@Override
	protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception {
		// 序列化对象
		byte[] bytes = serializerUtil.serializer(msg);
		// 输出信息长度
		out.writeInt(bytes.length);
		// 输出信息
		out.writeBytes(bytes);
	}
}
